<%@ page import="cn.js.fan.util.ParamUtil" %>
<%@ page import="com.redmoon.oa.person.UserDesktopSetupDb" %>
<%@ page import="cn.js.fan.util.StrUtil" %>
<%@ page import="com.redmoon.oa.sys.DebugUtil" %>
<%@ page import="com.redmoon.oa.flow.FormDb" %>
<%@ page import="com.redmoon.oa.visual.FormDAO" %>
<%@ page import="com.redmoon.oa.visual.ModuleSetupDb" %>
<%@ page import="com.redmoon.oa.flow.FormField" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.redmoon.oa.visual.ModuleUtil" %>
<%@ page import="cn.js.fan.util.ErrMsgException" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.redmoon.oa.chart.ChartUtil" %>
<%@ page import="com.redmoon.oa.chart.Line" %>
<%@ page contentType="text/html;charset=utf-8" %>
<%
    int id = ParamUtil.getInt(request, "id", -1);
    UserDesktopSetupDb udsd = new UserDesktopSetupDb();
    udsd = udsd.getUserDesktopSetupDb(id);

    long chartId = StrUtil.toLong(udsd.getMetaData(), -1);
    if (chartId == -1) {
        out.print("未设置关联的图形");
        DebugUtil.e(getClass(), "桌面：", udsd.getTitle() + " 未设置关联的图形！");
        return;
    }

    FormDb fdChart = new FormDb();
    fdChart = fdChart.getFormDb(ChartUtil.CONFIG_CHART);
    FormDAO fdaoChart = new FormDAO();
    fdaoChart = fdaoChart.getFormDAO(chartId, fdChart);

    String legend1 = fdaoChart.getFieldValue("legend1"); // 图例1
    String legend2 = fdaoChart.getFieldValue("legend2"); // 图例2

    Line line = null;
    try {
        line = ChartUtil.getDataForLine(request, fdaoChart);
    } catch (ErrMsgException e) {
        out.print(e.getMessage());
        return;
    }

    JSONArray arr = null;
    if (line.isSimpleData()) {
        arr = line.getData();
    }
    else {
        arr = line.getData1();
    }
    boolean isData2 = false;
    JSONArray data2 = line.getData2();
    if (data2 != null) {
        isData2 = true;
    }
%>
<script>
    // 实例化一个JS数组
    var xItems = new Array();
    var yItems = new Array()
    var yItems2 = new Array();
    // 循环遍历Java数组
    <%
        for (int i = 0; i < arr.size(); i++) {
            JSONObject json = arr.getJSONObject(i);
    %>
    // 将Java数组中的值赋给JS数组
    xItems[<%=i%>] = '<%=json.getString("name")%>';
    yItems[<%=i%>] = '<%=json.getString("value")%>';
    <%
            if (isData2) {
                JSONObject json2 = data2.getJSONObject(i);
    %>
    yItems2[<%=i%>] = '<%=json2.getString("value")%>';
    <%
            }
         }
    %>
</script>
<div id="drag_<%=id%>" class="portlet drag_div bor ibox" style="padding:0;">
    <div id="drag_<%=id%>_h" class="drag-h" style="height:3px;padding:0;margin:0;font-size:1px"></div>
    <div class="ibox-title">
        <div class="chart-title">
            <h5>
                <i class="fa <%=udsd.getIcon()%>"></i>
                <span><%=udsd.getTitle()%></span>
            </h5>
        </div>
    </div>
    <div class="portlet_content ibox-content">
        <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
        <div id="lineBox<%=id%>" style="width: 360px;height:210px;"></div>
        <script type="text/javascript">
            //指定图标的配置和数据
            var option = {
                grid:{
                    x:55,
                    y:30,
                    x2:20,
                    y2:20,
                    borderWidth:0
                },
                /*title:{
                    text:'折线图'
                },*/
                tooltip:{},
                /*legend:{
                    data:['访客来源']
                },*/
                xAxis:{
                    data: xItems,
                    splitNumber:6,  // 设置x轴刻度间隔个数
                    boundaryGap: true
                },
                yAxis:{
                    name: '数值',
                    type: 'value',
                    min:0, // 设置y轴刻度的最小值
                    // max:1800,  // 设置y轴刻度的最大值
                    splitNumber:6,  // 设置y轴刻度间隔个数
                    /*axisLine: {
                        lineStyle: {
                            // 设置y轴颜色
                            color: '#87CEFA'
                        }
                    }*/
                },
                series:[{
                    name:'<%=legend1%>',
                    type:'line',
                    areaStyle: {
                        normal: {color: '#80ffc0'}
                    },
                    smooth: 0.5,
                    data: yItems
                }
                <%
                if (isData2) {
                %>
                ,{
                    name:'<%=legend2%>',
                    type:'line',
                        areaStyle: {
                        normal: {color: '#80ffc0'}
                    },
                    smooth: 0.5,
                    data: yItems2
                }
                <%
                }
                %>
                ]
            };
            //初始化echarts实例
            var myChart = echarts.init(document.getElementById('lineBox<%=id%>'));

            //使用制定的配置项和数据显示图表
            myChart.setOption(option);
        </script>
    </div>
</div>
